﻿using System;
using System.Collections.Generic;
using System.Linq;

using Fuse8.DomainFramework.Domain;

namespace Fuse8.ContentManagementFramework.Domain.Special
{
    [Serializable]
    public class CmsEntityMetaInformation : Int32EntityObject
    {
        [NonSerialized]
        private IList<CmsEntityMeta> _metas;

        public IList<CmsEntityMetaField> MetaFields { get; set; }

        public IList<CmsEntityMetaFieldLink> MetaFieldLinks { get; set; }

        public IList<CmsEntityMeta> Metas
        {
            get
            {
                if (_metas == null)
                {
                    _metas = new List<CmsEntityMeta>();
                }

                return _metas;
            }
            set
            {
                if (value != null)
                {
                    _metas = value;
                }
            }
        }

        public IEnumerable<CmsEntityMeta> DefaultMetas
        {
            get
            {
                //todo: investigate why we need default metas
                return /*MetaFieldLinks != null ?
                       MetaFieldLinks.Where(p => !string.IsNullOrWhiteSpace(p.MetaFieldValues))
                            .Select(p => new CmsEntityMeta
                            {
                                EntityMetaValue = p.MetaFieldValues,
                                EntityMetaFieldLink = p,
                                IsDefault = true
                            }) :*/
                        new List<CmsEntityMeta>();
            }
        }

        public IEnumerable<CmsEntityMeta> AllMetas
        {
            get
            {
                return (Metas ?? new List<CmsEntityMeta>()).Concat(DefaultMetas);
            }
        }

        public override string TypeParameter
        {
            get 
            {
                return "CmsEntityMetaInformation";
            }
        }
    }
}
